/*
 * SimplePanelImage.java
 * Copyright (C) 05/07/2006, 19:21 Francisco J. Hernández
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 */

package SimpleComponents;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.net.MalformedURLException;

/**
 *
 * @author  fran
 */
public class SimplePanelImage extends javax.swing.JPanel {
    
    private File imageFile;
    private Image backGround;
    private boolean image = false;
    
    /** Creates new form SimplePanelImage */
    public SimplePanelImage() {
        super();
        super.setOpaque(false);
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        setLayout(null);

    }// </editor-fold>//GEN-END:initComponents
    
    public void paint(Graphics g) {
        if (image)
            g.drawImage(backGround,0,0,this);
        super.paint(g);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    public Image getBackGround() {
        return backGround;
    }

    public void setBackGround(Image backGround) {
        this.backGround = backGround;
        image = true;
    }

    public File getImageFile() {
        return imageFile;
    }

    public void setImageFile(File imageFile) {
        this.imageFile = imageFile;
        try {
            //backGround = Toolkit.getDefaultToolkit().createImage(imagePath);
            backGround = Toolkit.getDefaultToolkit().createImage(imageFile.toURL());
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
        image = true;
    }
    
}
